<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> 
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>  
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="Cache" content="no-cache">
<meta http-equiv="expires" content="0"> 
<meta name="viewport" content ="width=device-width, initial-scale=1">
<%@ include file="JQMStyle.jsp"%>
<script>
var url = "http://www.qxbaby.cc:81/barcodePic/";
$(document).ready(function(){
	$("#barcode").focus();

})
document.onkeyup = BSkeyUp; 

function BSkeyUp(e){
	var ieKey = window.event ? e.keyCode : e.which;

	 if (ieKey==13){
	   if (e.target.id=="barcode"){
	       var barcode =$("#barcode").val();
	       e.returnValue=false;
	       if (barcode != ""){
	    	   SearchByBarcode();
	       }
	   } 
	 } 
} 

function searchByProductCode(){
	var productCode= $("#productCode").val(); 

	if (productCode.length >= 3){
		var params = "formBean.productCode=" + $("#productCode").val()+"&formBean.storeId=" + $("#storeId").val() + "&formBean.storeType=" + $("#storeType").val();

		$.mobile.loading("show",{ theme: "b", text: "正在加载数据", textonly: false});
		
		$.post('<%=request.getContextPath()%>/action/ipadJSON!searchProductByProductCode', params, 
		function(result) {
			backProcess(result);
			//clearSearch();
		}, 'JSON');
    }
}
function backProcess(result){
	if (result.returnCode == 2) {
	    $('#productBody tr').each(function () {                
	        $(this).remove();
	    });
	    
	    var cops = result.returnValue;

	    if (cops.length != undefined &&cops.length != 0){
		    for (var i = 0; i < cops.length; i++){
		        if (cops[i] != "")  {
			          $("<tr><td style='vertical-align:middle;'>"+
			        		  cops[i].brand + " " +  cops[i].category  +"</td><td style='vertical-align:middle;'>"+
			        		  cops[i].productCode + cops[i].color + "/ "+ cops[i].factoryCode + "/ "+cops[i].productIdentity +"</td><td style='vertical-align:middle;'>"+
			        		  "</td><td style='vertical-align:middle;'>"+"千禧价格: " + cops[i].salesPrice + "</td><td style='vertical-align:middle;'>" +
			        		  "批发价格:" + cops[i].wholeSalePrice+"</td><td style='vertical-align:middle;'>"+"</td><td style='vertical-align:middle;'>" +
			        		  "总部库存 :" + cops[i].inventory+"</td><td style='vertical-align:middle;'>"+
			        		  "<a href='"+cops[i].picURL+"' target='_blank'><img id='pic' src='"+cops[i].picURL+"' width='100' height='100' alt='图片无法加载'/></a></td>"+
					          "</tr>").appendTo("#productBody");
		        }
		    }
	    } else {
	    	$("<tr><td colspan=5><font color='red'>没有查询到条码信息</font> </td></tr>").appendTo("#productBody");
	    }
	    
	    $("#products").show();

	    $.mobile.loading("hide");
	} else {
		$.mobile.loading("hide");
		renderPopup("系统错误",result.msg);
	}
}
function clearSearch(){
	$("#barcode").focus();
	$("#barcode").val("");
	$("#productCode").val("");
}

function SearchByBarcode(){
	if (validateBarcodeSearch()){
		var barcode =$("#barcode").val();
		var params = "formBean.barcode=" + barcode+"&formBean.storeId=" + $("#storeId").val();

		$.mobile.loading("show",{ theme: "b", text: "正在加载数据", textonly: false});
		
		$.post('<%=request.getContextPath()%>/action/ipadJSON!searchProductByProductCode', params, 
		function(result) {
			backProcess(result);
			clearSearch();
		}, 'JSON');
	}
}

function validateBarcodeSearch(){

	if ($.trim($("#barcode").val()).length < 12){
		renderPopup("查询错误","条码长度错误 : " + $("#barcode").val());
		clearSearch();
		$("#barcode").focus();
		return false;
	} else 
		return true;
}




</script>
</head>
<body>
<!-- 按照品牌汇总的 MyOrder 汇总 -->
	<div id="myOrder" data-role="page">
		<script>
		    
		</script>
<div data-role="header" data-theme="b" data-position="fixed" data-tap-toggle="false">
      <a href="#" data-transition="fade" onclick="logoff();">退出登陆</a>
      <a href="#" data-rel="dialog" data-transition="fade" onclick="clearOrder();">重新开单</a>
	  <h4>商品信息查询</h4>
</div> 

		<div  data-role="content" class="content">
				<table>
				    <tr >
						<td width="12%"><label for="productCode">条码: </label></td> 
						<td><input id="barcode" name="barcode" placeholder="扫描条码"/></td>
						<td><select id="storeId" name="storeId">
							<option value="1">濛阳</option>
								<option value="2">质量问题</option>
								<option value="13">禧乐</option>
						</select></td>
						<td></td>
					</tr>
				    <tr>
						<td><label for="productCode">货号: </label></td> 
						<td><input type="text" id="productCode" name="productCode" placeholder="3位货号自动查询"  onkeyup="searchByProductCode();"/></td>
						<td ><select id="storeType" name="storeType"><option value="1">全部</option><option value="2">千禧</option><option value="3">禧乐仓</option></select></td>
						<td><input type="button" value="清除" onclick="$('#productCode').attr('value','');$('#productCode').focus();"/></td>
					</tr>                 
				</table>
				<div id="products" style="display:none">
					<table data-role="table" id="table-column-toggle" class="ui-responsive table-stroke">
					     <tbody id="productBody">
					     </tbody>
				    </table>	
				</div>	
		</div>


        <jsp:include  page="MobileFooter.jsp"/>
		<jsp:include  page="Popup.jsp"/>

	</div>

</body>
</html>